/*
 * 项目模块
 */

//获取项目列表
function projectLists(user_id) {
    var url = apiurl+"/projects/list";
    var urlData = {
        user_id:user_id,
        group_id:group_id
    }
    $.ajax({
        url:url,
        type:"GET",
        data:urlData,
        beforeSend:function(){
            $(".loading").show();
        },
        complete:function() {
            $(".loading").hide();
        },
        success:function(d){
            var comData = d;
            if (d.code == undefined) {
                comData = JSON.parse(d);
            }
            if (comData.code == 0) {
                var data = JSON.parse(d).data;
                if (data == "") {
                    $(".task-alert").text("当前无项目").show().fadeOut(2000);
                } else {
                    for (var i = 0; i < data.length; i++) {
                        var title = data[i].project_title;
                        var project_id = data[i].project_id;
                        $(".project-ul").append("<li class='project-li' project_id='" + project_id + "' project_title='" + title + "'> " +
                            "<img class='project-img' src='images/project/projectImg.png' />" +
                            "<span class='project-span'>" + title + "</span>" +
                            "<hr class='bottomLine' />" +
                            "</li>")
                    }
                    $(".projectContent-div").show();
                }
            }
            else {
                $(".task-alert").text("Error").show().fadeOut(2000);
            }
        },
        error:function(){
            $(".task-alert").text("网络不给力").show().fadeOut(2000);
        }
    })
}

// 前往项目详情
$(document).on('click','.project-li',function(){
    var project_id = $(this).attr("project_id");
    var title = $(this).attr("project_title");
    window.location.href = "html/project/projectDetail.html?project_id="+project_id+"&tabbarCount=1";
})
